package net;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.List;

public class Receiver extends Thread{
	private Socket curSocket;
	private List<Socket> sockets;
	
	
	public Receiver(Socket curSocket, List<Socket> sockets) {		
		this.curSocket = curSocket;
		this.sockets = sockets;
	}


	@Override
	public void run() {
		while(true){
			try {
				ObjectInputStream ois=new ObjectInputStream(curSocket.getInputStream());
				String mess=(String) ois.readObject();
				System.out.println("rec"+mess);
				for (Socket socket : sockets) {
					ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
					oos.writeObject(mess);
					oos.flush();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}			
		}
	}
	
}
